package tech.horgee.entity;

import com.baomidou.mybatisplus.annotation.*;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import jakarta.validation.constraints.NotNull;
import lombok.Getter;
import lombok.Setter;
import tech.horgee.common.IWrapper;
import tech.horgee.group.UpdateGroup;

import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.Objects;

/**
 * 字典表
 *
 * @author haojun
 * @since 2024-01-03
 */
@Getter
@Setter
@TableName("tab_dict")
public class Dict implements Serializable, IWrapper<Dict> {

    private static final long serialVersionUID = 1L;

    /**
     * 主键
     */
    @NotNull(groups = UpdateGroup.class)
    @TableId(value = "id", type = IdType.AUTO)
    private Long id;

    /**
     * 名称
     */
    private String name;

    /**
     * 值
     */
    private String value;

    /**
     * 创建时间
     */
    @TableField(updateStrategy = FieldStrategy.NEVER)
    private LocalDateTime createTime;

    /**
     * 更新时间
     */
    @TableField(updateStrategy = FieldStrategy.NEVER)
    private LocalDateTime updateTime;


    @Override
    public LambdaQueryWrapper<Dict> wrapper() {
        return new LambdaQueryWrapper<Dict>()
                .eq(Objects.nonNull(id), Dict::getId, id)
                .like(Objects.nonNull(name), Dict::getName, name)
                .like(Objects.nonNull(value), Dict::getValue, value)
                .eq(Objects.nonNull(createTime), Dict::getCreateTime, createTime)
                .eq(Objects.nonNull(updateTime), Dict::getUpdateTime, updateTime)
                ;
    }
}
